package com.wangp.mywrite.inwork.pattern._2._2_2_advanced_char;

/***
 * @author wangpeng
 * @since 2022-02-28  11:49
 */
public class AdvancedChar {

    public static void main(String[] args) {
        // 简洁正则表达方式。
        // 如：
        // [0-9] -> \d
        // [^0-9] -> \D
        String digitalReg = "\\d";
        String notDigitalReg = "\\D";

        System.out.println("1 匹配 \\d :" + "1".matches(digitalReg));
        System.out.println("a 匹配 \\D :" + "a".matches(notDigitalReg));
        System.out.println("10 匹配 \\d :" + "10".matches(digitalReg));

        // [a-zA-z0-9_] -> \w   任何一个字母数字字符或者下划线
        // [^a-zA-z0-9_] -> \W  任何一个非字母数字字符或者非下划线
        String wReg = "\\w";
        String noWReg = "\\W";
        System.out.println("H 匹配 \\w :" + "H".matches(wReg));
        System.out.println(". 匹配 \\W :" + ".".matches(noWReg));

        // 空白字符 \s -> [\f\n\r\t\v]
        // 非空字符 \S -> [^\f\n\r\t\v]
        String sReg = "\\s";
        String noSReg = "\\S";
        System.out.println("空格 匹配 \\s :" + " ".matches(sReg));
        System.out.println("A 匹配 \\S :" + "A".matches(noSReg));

        // 匹配16进制数
        String hexReg = "0x[0-9A-Fa-f]+";
        System.out.println("0xFF 匹配 16进制：" + "0xFF".matches(hexReg));
        System.out.println("0xF6F1 匹配 16进制：" + "0xF6F1".matches(hexReg));
        System.out.println("66 匹配 16进制：" + "66".matches(hexReg));

        // POSIX [[:digit:]] [[:alpha:]]
    }
}
